package com.prx.ObjectIO;

import java.io.*;

public class TestDemo {

    public static void main(String[] args) {
        test1();
    }
    /**
     * 对象流和序列化、transient关键字
     */
    public static void test1() {
        //创建一个Teacher对象
        Teacher teacher = new Teacher();
        //设置
        teacher.setTeaName("张三");
        teacher.setTeaNum("10252");
        teacher.setTeaSore(89.0);
        try {
            ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("E:/作业/a.txt"));
            //写出对象
            objectOutputStream.writeObject(teacher);
            System.out.println("将teacher对象从内存中写出到文件了");
            System.out.println(teacher);
            System.out.println("-----------------------------");
            ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("E:/作业/a.txt"));
            //读入对象流
            Object objIn = objectInputStream.readObject();
            Teacher teacher1 =  (Teacher)objIn;
            System.out.println("读入了对象流：");
            System.out.println(objIn);
            //写出的teacher对象和读入对象流是同一个对象
            System.out.println("teacher==objIn:"+(teacher==objIn));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
